<template>
  <div class="goods-list">
    <div
      class="goods-item"
      v-for="item in goodsList"
      @click="handlerClick(item.proid)"
    >
      <img :src="item.img1" alt="" />
      <p class="name">{{ item.proname }}</p>

      <p class="price">价格: {{ item.originprice }}</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

type GoodsType = {
  proid: string
  img1: string
  proname: string
  originprice: string
  [propName: string]: any
}

const router = useRouter()
const props = defineProps<{
  goodsList: GoodsType[]
}>()

const handlerClick = (id) => {
  router.push(`/detail/${id}`)
}
</script>

<style scoped lang="scss">
.goods-list {
  margin: 10px;
  .goods-item {
    width: 50%;
    box-sizing: border-box;
    padding: 5px;
    float: left;

    font-size: 0.8em;

    img {
      width: 80%;
      display: block;
    }
    .name {
      color: #333;
      height: 3em;
      line-height: 1.5em;

      border-radius: 5px solid red;
      -webkit-line-clamp: 2; // 两行省略号
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    // .name {
    //   color: #333;
    //   height: 3em;
    //   line-height: 1.5em;
    //   overflow: hidden;

    //   border: 1px solid red;

    //    // 单行省略号
    //   text-overflow: ellipsis;
    //   white-space: nowrap;
    // }

    .price {
      color: red;
      font-weight: 900;
    }
  }
}
</style>
